 public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int middle = (left + right) / 2;
        if (nums[left] == target) return left;
        if (nums[right] == target) return right;
        while (right - left > 1) {
            if (nums[left] == target) return left;
            if (nums[right] == target) return right;
            if (nums[middle] < target) {
                left = middle;
                middle = (left + right) / 2;
            } else if (nums[middle] > target) {
                right = middle;
                middle = (left + right) / 2;
            } else if (nums[middle] == target) {
                return middle;
            }
        }
        return -1;
    }